package yz;

import java.util.Objects;

/**
 * [剑指 Offer 58 - I. 翻转单词顺序](https://leetcode-cn.com/problems/fan-zhuan-dan-ci-shun-xu-lcof/)
 *
 * @author Yz
 * @since 2022-09-08 9:09
 */
public class LeetCode58_ReverseWords {
    
    private String reverseWords(String s) {
        if (s == null || Objects.equals("", s)) {
            return "";
        }
        StringBuilder sb = new StringBuilder();
        String[] split = s.split(" ");
        for (int i = split.length - 1; i >= 0; i--) {
            if (Objects.equals(split[i], "")) continue;
            sb.append(split[i]).append(" ");
        }
        return sb.toString().trim();
    }
}

